#pragma once

namespace patterns {

	template <typename T>
	class EmptyInitializer
	{
	public:
		EmptyInitializer(T&)
		{
		}
	};

	template < typename T, class TInitializer = EmptyInitializer<T> >
	class Singleton
	{
	public:
		static T& Instance()
		{
			LOCK(ins_cs);

			static T inst;
			static TInitializer init(inst);

			return inst;
		}

	protected:
		Singleton() {}
		~Singleton() {}

	private:
		Singleton(Singleton const&);
		Singleton& operator=(Singleton const&);

	protected:
		typedef Singleton creator;

	private:
		static CriticalSection ins_cs;
	};

	template <typename T, class TInitializer>
	CriticalSection Singleton<T,TInitializer>::ins_cs;

} // namespace patterns
